package com.game.business.common;

import com.game.center.respository.AsyncPlayerRespository;
import com.game.center.respository.PlayerRespository;
import com.game.common.concurrent.GameEventExecutorGroup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

@Configuration
public class BeanConfiguration {

    @Autowired
    private ServerConfig serverConfig;//注入配置信息

    private GameEventExecutorGroup dbExecutorGroup;
    @Autowired
    private PlayerRespository playerRespository; //注入数据库操作类

    @PostConstruct
    public void init() {
        dbExecutorGroup = new GameEventExecutorGroup(serverConfig.getDbThreads());//初始化db操作的线程池组
    }

    @Bean
    public AsyncPlayerRespository asyncPlayerRespository() {//配置AsyncPlayerDao的Bean
        return new AsyncPlayerRespository(dbExecutorGroup, playerRespository);
    }
}
